<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
use yii\widgets\Pjax;
use yii\grid\GridView;
use kartik\export\ExportMenu;

/* @var $this yii\web\View */
/* @var $searchModel app\models\ProjectSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '项目';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="project-index">

    <?php //echo $this->render('_search', ['model' => $searchModel]);   ?>


    <div class="col-md-12" style="margin-bottom: 12px">      
        <?php
        $form = ActiveForm::begin([
                    'action' => ['index'],
                    'method' => 'get',
                    'options' => ['class' => 'input-group chargeman'],
                    'fieldConfig' => [
                        'template' => '<div class="col-lg-12">{input}</div>',
                    ]
        ]);
        ?>

        <div class="col-md-4">
            <label style="float: left;margin-top: 5px;">项目名称</label>
            <div style="overflow: hidden;">
                <?php
                $datas = app\models\Project::find()->all();
                if ($datas != null) {
                    foreach ($datas as $item) {
                        $source[] = $item->projectname;
                    }
                } else {
                    $source[] = array();
                }
                echo yii\jui\AutoComplete::widget([
                    'model' => $searchModel,
                    'attribute' => 'projectname',
                    'options' => ['style' => 'margin-left:10px'],
                    'clientOptions' => [
                        'source' => $source,
                    ],
                ]);
                ?>        
            </div>
        </div>
        <div class="col-md-4">
            <label style="float: left;margin-top: 5px;">项目负责人</label>
            <div style="overflow: hidden;">
                <?php
                if ($datas != null) {
                    foreach ($datas as $item) {
                        $source[] = $item->chargeman;
                    }
                } else {
                    $source[] = array();
                }
                echo yii\jui\AutoComplete::widget([
                    'model' => $searchModel,
                    'attribute' => 'chargeman',
                    'options' => ['style' => 'margin-left:10px'],
                    'clientOptions' => [
                        'source' => $source,
                    ],
                ]);
                ?>    
            </div>
        </div>

        <div class="col-md-3">
            <label style="float: left;margin-top: 5px;">纵横向类型</label>
            <div style="overflow: hidden;">
                <?php
                echo $form->field($searchModel, 'zhxtype')->dropDownList(['纵向项目' => '纵向项目', '横向项目' => '横向项目'], ['prompt' => '全部']);
                ?>        
            </div>
        </div>

        <div class="col-md-1">
            <?= Html::submitButton(' 搜索', ['class' => 'btn btn-primary glyphicon glyphicon-search']) ?> 
        </div>

    </div>


    <div class="col-md-5 text-right" style="margin: 10px 0 15px 15px;float: right;padding-right: 0">

        <?php echo Html::a('新建项目', ['create'], ['class' => 'btn btn-primary']) ?> 
        <button class="btn btn-default glyphicon glyphicon-print" onclick="printme()"> 打印</button>
        <span>&nbsp;&nbsp;</span>

        <!--为什么要多加一个form才可以导出呢？？？-->
        <?php
        $form = ActiveForm::begin([
                    'action' => ['index'],
                    'options' => ['enctype' => 'multipart/form-data', 'id' => 'form2', 'name' => 'form2']
                ])
        ?>
        <?php ActiveForm::end(); ?>

        <?Php
        echo ExportMenu::widget([
            'dataProvider' => $dataProvider,
            'dropdownOptions' => [
                'label' => '导出Excel',
                'class' => 'btn btn-default',
                'icon' => '',
            ],
            'showColumnSelector' => false,
            'exportConfig' => [
                ExportMenu::FORMAT_TEXT => false,
                ExportMenu::FORMAT_PDF => false,
                ExportMenu::FORMAT_CSV => false,
                ExportMenu::FORMAT_EXCEL_X => false,
                ExportMenu::FORMAT_HTML => false
            ],
            'columns' => [
                ['class' => 'yii\grid\SerialColumn'],
//                'id',
                'projectno',
                'projectname',
                'userid',
                'chargeman',
                'unit',
                'projectfrom',
                'zhxtype',
                'projectlevel',
                'projectplantype',
                'discipline',
                'status',
                'projectmember',
                'isfinish',
                'updatetime',
                'addman',
                'addmanid',
                'addtime',
                'jf_dxjf',
                'jf_zzjf',
                'jf_jhnhx',
                'jf_jhwhx',
                'jf_sbgzf',
                'jf_zcjf',
                'jf_ppf',
                'jf_zcjfhj',
                'jf_syjf',
                'member',
                'projectmoney',
                'mark',
            ]
        ]);
        ?>
    </div>


    <?php ActiveForm::end(); ?>

    <!--加载上传文件的对话框-->
    <?= $this->render('/upload/upload', ['model' => $model]) ?>


    <?php Pjax::begin(); ?>
    <?=
    GridView::widget([
        'id' => 'tableContainer',
        'tableOptions' => ['class' => 'table table-bordered'],
        'rowOptions' => [
            'style' => '
                        border-bottom: 18px solid #EFEFEF;
                        '],
        'headerRowOptions' => [
            'style' => 'font-size: 15px;color: #2a70e9;background-color: #D9EDF7;',
        ],
        'layout' => "{items}\n{pager}",
        'dataProvider' => $dataProvider,
        'columns' => [
            // ['class' => 'yii\grid\SerialColumn'],
            'projectno',
            [
                'attribute' => 'projectname',
                'label' => '项目名称',
                'format' => 'raw',
                'value' => function ($model) {
                    return Html::a($model->projectname, ['project/view', 'id' => $model->id]);
                },
                        'contentOptions' => ['style' => ''],
                        'headerOptions' => ['style' => ''],
                    ],
                    'chargeman',
                    'zhxtype',
                    [
                        'attribute' => 'projectfrom',
                        'label' => '项目来源',
                        'format' => 'raw',
                        'contentOptions' => ['style' => ''],
                        'headerOptions' => ['style' => ''],
                    ],
                    [
                        'class' => 'yii\grid\ActionColumn',
                        'template' => '{update} {delete}',
                        'buttons' => [
                            //update button
                            'update' => function ($url) {
                                return Html::a('<span class="fa fa-search"></span>编辑', $url, [
                                            'title' => Yii::t('app', 'Update'),
                                                // 'class' => 'btn btn-primary btn-md',
                                ]);
                            },
                                    //update button
                                    'delete' => function ($url) {
                                return Html::a('<span class="fa fa-search"></span>删除', $url, [
                                            'title' => Yii::t('app', 'Delete'),
                                            'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                                            'data-method' => 'post',
                                            'data-pjax' => '0',
                                                //  'class' => 'btn btn-primary btn-md',
                                ]);
                            },
                                ],
                            ],
                        ],
                    ]);
                    ?>



                    <?php Pjax::end(); ?>
</div>
<script>
    var global_Html = "";
    function printme() {
        global_Html = document.body.innerHTML;
        document.body.innerHTML = $('#tableContainer').html();
        $('.btn').hide();
        $('.pagination').hide();
        $('a').each(function () {
            $(this).replaceWith($(this).html());
        });
        window.print();
        window.setTimeout(function () {
            document.body.innerHTML = global_Html;
        }, 300);
    }
</script>


<style type="text/css">
    /*    .time_table_top td {
            font-size: 15px;
            color: #2a70e9;
            background-color: #d9edf7;
        }*/
</style>
